package group2assignone.view.manager;

import group2assignone.func.MyCheckBox;
import group2assignone.view.OurView;
import java.awt.*;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.border.EtchedBorder;

/**
 *
 * @author Flick
 */
public class ListLoggedInView extends OurView {

//    private JLabel custLab;
    private JButton getDetails = new JButton("Book Flight");
    private JButton cancel = new JButton("Cancel");
    private JLabel flights;
//    private Customer customer;
    private String selectedMember;
    private CheckboxGroup cbg = new CheckboxGroup();
    private ArrayList<String> loggedInMembers;

    /**
     * Customer used for personalisation. If customer is not logged in
     * then username is 'Guest'
     * @param cust
     */
//    public ListLoggedInView(Customer cust) {
//        customer = cust;
//    }
    /**
     * Function to add the GUI components to the frame.
     */
    @Override
    public void addComponents() {

        setTitle("Logged In Members");
//        custLab = new JLabel("Welcome " + customer.getUsername());

//        northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.LINE_AXIS));
//        custLab.setAlignmentX(JLabel.LEFT);
//        logout.setAlignmentX(JButton.RIGHT);
//        northPanel.add(custLab);
//        northPanel.add(Box.createHorizontalGlue());
//        northPanel.add(logout);
//        northPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));

        southPanel.add(getDetails);
        southPanel.add(cancel);

        eastPanel.setBorder(BorderFactory.createEmptyBorder(20, 10, 20, 20));
        westPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 10));
        northPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
        southPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));

//        logout.addActionListener(new UCCtoALAdapter(new UCLogout(this)));
//        bookFlight.addActionListener(new UCCtoALAdapter(new UCUIBookFlight(customer, this)));
//        if (customer.getUsername().equals("Guest")) {
//            cancel.addActionListener(new UCCtoALAdapter(new UCCancelGuest(this)));
//        } else {
//            cancel.addActionListener(new UCCtoALAdapter(new UCCancelCust(customer, this)));
//        }
    }

    /**
     * displays a list of flights provided in the middle panel
     * displays as check box options so only one can be selected
     * @param loggedIn 
     */
    public void displayFlights(ArrayList<String> loggedIn) {
        int size = loggedIn.size();
        loggedInMembers = loggedIn;
        centerPanel.setLayout(new GridLayout(size + 1, 3, 10, 5));
        centerPanel.add(new JLabel("Select"));
        centerPanel.add(new JLabel("User Name"));
        centerPanel.add(new JLabel("Password"));
        for (int i = 0; i < size; i++) {
            String[] temp = loggedInMembers.get(i).split(",");
            centerPanel.add(new MyCheckBox("", true, cbg, i));
            centerPanel.add(new Label(temp[0]));
            centerPanel.add(new Label(temp[1]));
        }
    }

    /**
     *
     * @return the flight currently selected in the check box group
     */
    public String getSelectedUserName() {
        MyCheckBox mcb = (MyCheckBox) cbg.getSelectedCheckbox();
        int i = mcb.getIndex();
        String[] temp = loggedInMembers.get(i).split(",");
        return temp[0];
    }
}
